package com.fdb.efp.esb.service.impl.loan;

import com.fdb.efp.esb.common.client.resp.EsbRespServiceBean;
import com.fdb.efp.esb.common.constant.EsbBizEnums;
import com.fdb.efp.esb.common.constant.loan.PerLoanConstant;
import com.fdb.efp.esb.service.facade.loan.PerLoanSysLoanBalanceService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.fdb.basic.framework.core.exception.ESBException;
import com.fdb.basic.framework.core.util.TraceUtil;
import com.fdb.efp.esb.service.bo.req.loan.PerLoanSysLoanBalanceReqBean;
import com.fdb.efp.esb.service.bo.resp.loan.PerLoanSysLoanBalanceRespBean;
import com.fdb.efp.esb.service.client.ESBClientFactory;

/**
 * 需求编号：【额度管控】
 * 问题编号：【暂无】
 * 开发人员：【ludayong】
 * 创建/修改日期：【2019/9/23】
 * 修改描述：根据身份证、证件类型查询个贷查询贷款借据余额信息
 * 
 **/
@Service("perLoanSysLoanBalanceService")
public class PerLoanSysLoanBalanceServiceImpl implements PerLoanSysLoanBalanceService {
	private static Logger logger = LoggerFactory.getLogger(PerLoanSysLoanBalanceServiceImpl.class);

	@Override
	public PerLoanSysLoanBalanceRespBean applyPerLoanSysLoanBalance(PerLoanSysLoanBalanceReqBean perLoanSysLoanBalanceReqBean)
			throws ESBException {
		logger.info("======>调用个贷查询贷款借据余额信息查询接口【" + TraceUtil.getGlblSrlNo() + "_30230003_13】开始<======");
		PerLoanSysLoanBalanceRespBean perLoanSysLoanBalanceRespBean = null;
		try {
			EsbRespServiceBean recvBean = ESBClientFactory.buildClient().withBody(perLoanSysLoanBalanceReqBean).withTradeNo(PerLoanConstant.TRADE_NO_30230003)
					.withScene(PerLoanConstant.SECNE_NO_13).create().sendAndReceive();
			if (EsbBizEnums.RetCodeEnum.SUCCESS.VALUE.equals(recvBean.getSysHead().getRetInfArry().get(0).getRetCd())) {
				perLoanSysLoanBalanceRespBean = recvBean.getBody(PerLoanSysLoanBalanceRespBean.class);
			} else {
				throw new ESBException(recvBean.getSysHead().getRetInfArry().get(0).getRetMsg());
			}
			logger.info("调用个贷查询贷款借据余额信息查询接口【30230003_13】结束，返回信息：" + JSONObject.toJSONString(perLoanSysLoanBalanceRespBean));
		} catch (Exception e) {
			logger.error("调用个贷查询贷款借据余额信息查询接口【30230003_13】出现异常：" + e.getMessage());
			throw new ESBException("调用个贷查询贷款借据余额信息查询接口【30230003_13】出现异常：" + e.getMessage());
		} finally {
			logger.info("======>调用个贷查询贷款借据余额信息查询接口【" + TraceUtil.getGlblSrlNo() + "_30230003_13】结束<======");
		}
		return perLoanSysLoanBalanceRespBean;
	}
}